﻿using System.Configuration;
using System.Web;
using jSLApp.Web.Workflow;

namespace jSLApp.Web
{
    /// <summary>
    /// Summary description for PaymentHandler
    /// </summary>
    public class PaymentHandler : IHttpHandler
    {

        public void ProcessRequest(HttpContext context)
        {
            context.Response.ContentType = "text/plain";

            var paymentKey = ConfigurationManager.AppSettings["paymentKey"];
            var key = context.Request.QueryString["key"];
            if(key.ToUpper()!=paymentKey.ToUpper())
            {
                context.Response.Write("Не правильный ключ");
                return;
            }

            var userName = context.Request.QueryString["userName"];
            var info = context.Request.QueryString["Info"];
            var money = context.Request.QueryString["Money"];
            using (var db = new DB())
            {
                var user = MainService.GetUser(db,userName);

                var payment = user.PayForBalance(decimal.Parse(money), info);

                db.SubmitChanges();
            }

            context.Response.Write("Платёж прошел успешно.");
        }

        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }
}